let wrap = document.getElementById("wrap"),
  count = 0;
function doSomething(e) {
  wrap.innerHTML = count++;
  return '111'
}
wrap.onmousemove = debounce(doSomething, 300);
// 防抖
function debounce(fn, wait, immediate) {
  let timeOut, res;
  let debounced = function () {
    let _self = this,
      args = arguments;
    clearTimeout(timeOut);
    if (immediate) {
      let callNow = !timeOut;
      timeOut = setTimeout(function () {
        timeOut = null;
      }, wait);
      if (callNow) res = fn.apply(_self, args);
    } else {
      timeOut = setTimeout(function () {
        fn.apply(_self, args);
      }, wait);
    }
    return res;
  };
  debounced.cancel = function () {
    clearTimeout(timeOut);
    timeOut = null;
  };
  return debounced;
}
